package com.love.cloud.admin.controller;

import com.love.cloud.admin.api.vo.MessageHandleReadVo;
import com.love.cloud.admin.service.NoticeMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Set;

/**
 * @author hongdongqu
 */
@RequestMapping("/notice/message")
@Api(tags = "通知消息中心")
@RestController
public class NoticeMessageController {
    @Resource
    private NoticeMessageService noticeMessageService;
    @ApiOperation(value = "获取到消息列表（分页）")
    @GetMapping("/getMessagePageByKey")
    public Object getMessagePageByKey(String keyValue,String keyType){
        return noticeMessageService.getMessagePageByKey(keyValue,keyType);
    }

    @ApiOperation(value = "已读接口")
    @PutMapping("/handleRead")
    public Object handleRead(@Validated({MessageHandleReadVo.Handle.class}) @RequestBody MessageHandleReadVo messageHandleReadVo){
        return noticeMessageService.handleRead(messageHandleReadVo);
    }

    @ApiOperation(value = "全部已读接口")
    @PutMapping("/allHandleRead")
    public Object allHandleRead(@Validated({MessageHandleReadVo.AllHandle.class})@RequestBody MessageHandleReadVo messageHandleReadVo){
        return noticeMessageService.allHandleRead(messageHandleReadVo);
    }

    @ApiOperation(value = "获取到未读办件的数量")
    @GetMapping("/getUnReadNum")
    public Object getUnReadNum(String keyValue,String keyType){
        return noticeMessageService.getUnReadNum(keyValue,keyType);
    }

    @GetMapping("/sendAdmin")
    public Object sendAdmin(){
        String content="测试";
        Long relationId=1000L;
        String relationType="测试模块";
        Set<String> keyValues =new HashSet<String>();
        String s1 = "1";
        keyValues.add(s1);
        String keyType="userId";
        return noticeMessageService.saveMessage(content,relationId,relationType,keyValues,keyType);
    }

}
